# tools/read_file.py
""" 
author: Men Dong Yang
create_time: 2025/6/19 16:08:40
description: 
"""
import csv
import os


def read_txt(file_path):
    # 拼接路径
    current = os.path.dirname(__file__)
    filename = os.path.join(current, '../', file_path)
    with open(filename, 'r') as f:
        file = f.read()  # 读取txt文件的所有内容,只写1行
        return file


def read_host():
    return read_txt('config/host.txt')


def read_token():
    return read_txt('config/token.txt')


def read_csv(file_path):
    # 拼接路径
    current = os.path.dirname(__file__)
    # 当前目录向上一级,找到file路径
    file_path = os.path.join(current, '../', file_path)
    # 打开文件
    with open(file_path, 'r', encoding='UTF-8') as f:
        # 读取文件
        rows = csv.reader(f)
        # 创建一个列表,用来存储csv文件中的数据
        data = []
        # 循环遍历文件中的每一行,并将其添加到列表中
        for row in rows:
            data.append(row)
        # 删除第一行
        data.pop(0)
        return data


if __name__ == '__main__':
    print(read_host())
